// Copyright 2007 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package lichen.internal;


/**
 * 类的常用处理方法
 * @author <a href="mailto:jun.tsai@gmail.com">Jun Tsai</a>
 * @version $Revision: 72 $
 * @since 0.0.1
 */
public class ClazzUtils {
	/**
	 * 得到持久化类的名称。
	 * 
	 * @param entity
	 *            待处理的持久化类。
	 * @return 持久化类的名称。
	 * @since 0.0.1
	 */
	public static Class getEntityClass(Object entity) {
		if (entity.getClass().getName().contains("CGLIB")) {
			return entity.getClass().getSuperclass();
		}
		return entity.getClass();
	}
	/**
	 * 通过给定的类名来构造一个实体类.
	 * @param clazzName 类名.
	 * @return 实体对象.
	 * @since 0.0.3
	 */
	public static Object newInstance(String clazzName){
		try {
			return Class.forName(clazzName)
					.newInstance();
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}
}
